package com.pro.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.pro.beans.Alarm;
import com.pro.beans.Page;
import com.pro.beans.Person;
import com.pro.beans.Polling;
import com.pro.dao.PersonDao;
import com.pro.dao.PollingDao;
import com.pro.mybatis.ListPage;
import com.pro.mybatis.MyBatisExpression;
import com.pro.mybatis.SearchCondition;
import com.pro.param.RequestParam;

@Service
public class PollingService {

	
	@Resource
	public PollingDao pollingDao;
	
	@Resource
	public PersonDao personDao;
	
	public List<Person> personList(){
		return personDao.getObjectsByPage(new Page());
	}
	
	public void addPolling(Polling polling){
		pollingDao.addObject(polling);
	}
	public void updatePolling(Polling polling){
		pollingDao.updateObject(polling);
	}
	public Polling getPollingById(Integer id){
		return pollingDao.getObject(id);
	}
	//巡检
	public void setPerson(Integer pollingId,Integer personId){
		Polling polling = new Polling();
		polling.setId(pollingId);
		polling.setPerson_id(personId);
		pollingDao.updateObject(polling);
	}
	public ListPage loadPollingList(RequestParam requestParam) {
		ListPage page = requestParam.getPage();
		SearchCondition sc = new SearchCondition();
		if (page == null || page.getTotal() == null) {
			page = new ListPage<Polling>();
		}
		page.setTotal(pollingDao.getTotal(sc));
	/*	sc.and(MyBatisExpression.bt("alarm_time",
				requestParam.getStart_alarm_time(), true));
		sc.and(MyBatisExpression.lt("alarm_time",
				requestParam.getEnd_alarm_time(), true));
		sc.and(MyBatisExpression.eq("type", requestParam.getType()));
		sc.and(MyBatisExpression.like("company_name",
				requestParam.getKey_word()));*/
		sc.and(MyBatisExpression.like("p_desc", requestParam.getKey_word()));
		sc.and(MyBatisExpression.like("address", requestParam.getKey_word()));
		sc.and(MyBatisExpression.eq("status", requestParam.getType()));
		sc.setPage(page);
		List<Polling> alarmList = pollingDao.loadAlarmListBySearchCd(sc);
		page.setDataList(alarmList);
		return page;
	}
}
